Test Setup Failed
Push — master ( 51607c...6b8ca8 )
by Paul
03:43
created

GLSR.showFormErrors   C

Complexity

Conditions 7
Paths 9

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
rs 6.7272
c 0
b 0
f 0
cc 7
nc 9
nop 1
1
GLSR.SCROLL_TIME = 468;
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2
GLSR.activeForm = null;
3
GLSR.recaptcha = {};
4
5
GLSR.buildFormData = function( recaptchaToken )
6
{
7
	if( recaptchaToken === undefined ) {
8
		recaptchaToken = '';
9
	}
10
	// console.log( 'recaptchaToken: ' + recaptchaToken );
11
	return {
12
		action: site_reviews.action,
0 ignored issues
show
Bug introduced by
The variable site_reviews seems to be never declared. If this is a global, consider adding a /** global: site_reviews */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
13
		request: GLSR.parseFormData( GLSR.activeForm ),
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
14
		'g-recaptcha-response': recaptchaToken,
15
	};
16
};
17
18
GLSR.clearFieldError = function( el )
19
{
20
	var fieldEl = el.closest( '.glsr-field' );
21
	if( fieldEl === null )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
22
	var errorEl = fieldEl.querySelector( '.glsr-field-errors' );
23
	GLSR.removeClass( fieldEl, 'glsr-has-error' );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
24
	if( errorEl !== null ) {
25
		errorEl.parentNode.removeChild( errorEl );
26
	}
27
};
28
29
GLSR.clearFormErrors = function()
30
{
31
	var formEl = GLSR.activeForm;
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
32
	GLSR.clearFormMessages();
33
	for( var i = 0; i < formEl.length; i++ ) {
34
		GLSR.clearFieldError( formEl[i] );
35
	}
36
};
37
38
GLSR.clearFormMessages = function()
39
{
40
	var messageEl = GLSR.activeForm.querySelector( '.glsr-form-messages' );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
41
	if( messageEl ) {
42
		messageEl.innerHTML = '';
43
	}
44
};
45
46
GLSR.createExceprts = function( parentEl )
47
{
48
	parentEl = parentEl || document;
49
	var excerpts = parentEl.querySelectorAll( '.glsr-hidden-text' );
50
	for( var i = 0; i < excerpts.length; i++ ) {
51
		var readmore = GLSR.insertAfter( excerpts[i], 'span', {
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
52
			'class': 'glsr-read-more',
53
		});
54
		var readmoreLink = GLSR.appendTo( readmore, 'a', {
55
			'href': '#',
56
			'data-text': excerpts[i].getAttribute( 'data-show-less' ),
57
		});
58
		readmoreLink.innerHTML = excerpts[i].getAttribute( 'data-show-more' );
59
	}
60
	GLSR.on( 'click', '.glsr-read-more a', GLSR.onClickReadMore );
61
};
62
63
GLSR.createStarRatings = function()
64
{
65
	var ratings = document.querySelectorAll( 'select.glsr-star-rating' );
66
	for( var i = 0; i < ratings.length; i++ ) {
67
		new StarRating( ratings[i], {
0 ignored issues
show
Bug introduced by
The variable StarRating seems to be never declared. If this is a global, consider adding a /** global: StarRating */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Unused Code Best Practice introduced by
The object created with new StarRating(ratings.i...earFieldError,false))}) is not used but discarded. Consider invoking another function instead of a constructor if you are doing this purely for side effects.
Loading history...
68
			clearable: false,
69
			showText : false,
70
			onClick  : GLSR.clearFieldError,
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
71
		});
72
	}
73
};
74
75
GLSR.enableSubmitButton = function()
76
{
77
	GLSR.activeForm.querySelector( '[type="submit"]' ).removeAttribute( 'disabled' );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
78
};
79
80
GLSR.getSelectorOfElement = function( el )
81
{
82
	if( !el || el.nodeType !== el.ELEMENT_NODE )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
83
	return el.nodeName.toLowerCase() +
84
		( el.id ? '#' + el.id.trim() : '' ) +
85
		( el.className ? '.' + el.className.trim().replace( /\s+/g, '.' ) : '' );
86
};
87
88
GLSR.now = function()
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
89
{
90
	return ( window.performance && window.performance.now ) ? window.performance.now() : Date.now();
91
};
92
93
GLSR.onClickPagination = function( ev )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
94
{
95
	ev.preventDefault();
96
	var parentEl = this.closest( '.glsr-reviews' );
97
	var parentSelector = GLSR.getSelectorOfElement( parentEl );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
98
	GLSR.addClass( parentEl, 'glsr-hide' );
99
	GLSR.getAjax( this.href, function( response ) {
100
		var html = document.implementation.createHTMLDocument( 'new' );
101
		html.documentElement.innerHTML = response;
102
		var newParentEl = parentSelector ? html.querySelectorAll( parentSelector ) : '';
103
		if( newParentEl.length === 1 ) {
104
			parentEl.innerHTML = newParentEl[0].innerHTML;
105
			GLSR.scrollToTop( parentEl );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
106
			GLSR.removeClass( parentEl, 'glsr-hide' );
107
			GLSR.on( 'click', '.glsr-ajax-navigation a', GLSR.onClickPagination );
108
			window.history.pushState( null, '', ev.target.href );
109
			GLSR.createExceprts( parentEl );
110
			return;
111
		}
112
		window.location = ev.target.href;
113
	});
114
};
115
116
GLSR.onClickReadMore = function( ev )
117
{
118
	ev.preventDefault();
119
	var el = ev.target;
120
	var hiddenNode = el.parentNode.previousSibling;
121
	var text = el.getAttribute( 'data-text' );
122
	GLSR.toggleClass( hiddenNode, 'glsr-hidden' );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
123
	GLSR.toggleClass( hiddenNode, 'glsr-visible' );
124
	el.setAttribute( 'data-text', el.innerText );
125
	el.innerText = text;
126
};
127
128
GLSR.recaptcha.addListeners = function()
129
{
130
	var overlayEl = GLSR.recaptcha.overlay();
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
131
	if( Object.prototype.toString.call( overlayEl ) === '[object HTMLDivElement]' ) {
132
		overlayEl.addEventListener( 'click', GLSR.enableSubmitButton, false );
133
		window.addEventListener( 'keyup', GLSR.recaptcha.onKeyup.bind( overlayEl ), false );
134
	}
135
};
136
137
GLSR.recaptcha.execute = function()
138
{
139
	var recaptchaId = GLSR.recaptcha.id();
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
140
	if( recaptchaId !== -1 ) {
141
		return grecaptcha.execute( recaptchaId );
0 ignored issues
show
Bug introduced by
The variable grecaptcha seems to be never declared. If this is a global, consider adding a /** global: grecaptcha */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
142
	}
143
	// recaptcha ID not found so pass through an error
144
	return GLSR.submitForm( false );
145
};
146
147
GLSR.recaptcha.id = function()
148
{
149
	return GLSR.recaptcha.search( function( value, id ) {
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
150
		if( Object.prototype.toString.call( value ) !== '[object HTMLDivElement]' )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
151
		if( value.closest( 'form' ) === GLSR.activeForm ) {
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Complexity Best Practice introduced by
There is no return statement if value.closest("form") === GLSR.activeForm is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
152
			return id;
153
		}
154
	});
155
};
156
157
GLSR.recaptcha.onKeyup = function( ev )
158
{
159
	if( ev.keyCode !== 27 )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
160
	GLSR.enableSubmitButton();
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
161
	GLSR.recaptcha.removeListeners( this );
162
};
163
164
GLSR.recaptcha.overlay = function()
165
{
166
	return GLSR.recaptcha.search( function( value ) {
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
167
		if( Object.prototype.toString.call( value ) !== '[object Object]' )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
168
		for( var obj in value) {
169
			if( !value.hasOwnProperty( obj ) || Object.prototype.toString.call( value[obj] ) !== '[object HTMLDivElement]' )continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
170
			if( value[obj].className === '' ) {
171
				return value[obj].firstChild;
172
			}
173
		}
174
		return false;
175
	});
176
};
177
178
GLSR.recaptcha.removeListeners = function( overlayEl )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
179
{
180
	overlayEl.removeEventListener( 'click', GLSR.enableSubmitButton, false );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
181
	window.removeEventListener( 'keyup', GLSR.recaptcha.onKeyup, false );
182
};
183
184
GLSR.recaptcha.reset = function()
185
{
186
	var recaptchaId = GLSR.recaptcha.id();
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
187
	if( recaptchaId !== -1 ) {
188
		grecaptcha.reset( recaptchaId );
0 ignored issues
show
Bug introduced by
The variable grecaptcha seems to be never declared. If this is a global, consider adding a /** global: grecaptcha */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
189
	}
190
};
191
192
GLSR.recaptcha.search = function( callback )
193
{
194
	var result = -1;
195
	if( window.hasOwnProperty( '___grecaptcha_cfg' )) {
196
		var clients = window.___grecaptcha_cfg.clients;
197
		var i, key;
198
		for( i in clients ) {
199
			for( key in clients[i] ) {
200
				if( !( result = callback( clients[i][key], i )))continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
201
				return result;
202
			}
203
		}
204
	}
205
	return result;
206
};
207
208
GLSR.scrollToTop = function( el, offset )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
209
{
210
	offset = offset || 16; // 1rem
211
	var fixedElement;
212
	for( var i = 0; i < site_reviews.ajaxpagination.length; i++ ) {
0 ignored issues
show
Bug introduced by
The variable site_reviews seems to be never declared. If this is a global, consider adding a /** global: site_reviews */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
213
		fixedElement = document.querySelector( site_reviews.ajaxpagination[i] );
214
		if( fixedElement && window.getComputedStyle( fixedElement ).getPropertyValue( 'position' ) === 'fixed' ) {
215
			offset = offset + fixedElement.clientHeight;
216
		}
217
	}
218
	var clientBounds = el.getBoundingClientRect();
219
	var offsetTop = clientBounds.top - offset;
220
	if( offsetTop > 0 )return; // if top is in view, don't scroll!
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
221
	if( 'requestAnimationFrame' in window === false ) {
222
		window.scroll( 0, window.pageYOffset + offsetTop );
223
		return;
224
	}
225
	GLSR.scrollToTopStep({
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
226
		endY: offsetTop,
227
		offset: window.pageYOffset,
228
		startTime: GLSR.now(),
229
		startY: el.scrollTop,
230
	});
231
};
232
233
GLSR.scrollToTopStep = function( context )
234
{
235
	var elapsed = ( GLSR.now() - context.startTime ) / GLSR.SCROLL_TIME;
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
236
	elapsed = elapsed > 1 ? 1 : elapsed;
237
	var easedValue = 0.5 * ( 1 - Math.cos( Math.PI * elapsed ));
238
	var currentY = context.startY + ( context.endY - context.startY ) * easedValue;
239
	window.scroll( 0, context.offset + currentY );
240
	if( currentY !== context.endY ) {
241
		window.requestAnimationFrame( GLSR.scrollToTopStep.bind( window, context ));
242
	}
243
};
244
245
GLSR.showFormErrors = function( errors )
246
{
247
	if( !errors )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
248
	var fieldEl, errorsEl;
249
	for( var error in errors ) {
250
		if( !errors.hasOwnProperty( error ))continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
251
		fieldEl = GLSR.activeForm.querySelector( '[name="' + error + '"]' ).closest( '.glsr-field' );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
252
		GLSR.addClass( fieldEl, 'glsr-has-error' );
253
		errorsEl = fieldEl.querySelector( '.glsr-field-errors' );
254
		if( errorsEl === null ) {
255
			errorsEl = GLSR.appendTo( fieldEl, 'span', {
256
				'class': 'glsr-field-errors',
257
			});
258
		}
259
		for( var i = 0; i < errors[ error ].errors.length; i++ ) {
260
			if( errors[ error ].errors[i] === null )continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
261
			errorsEl.innerHTML += '<span class="glsr-field-error">' + errors[ error ].errors[i] + '</span>';
262
		}
263
	}
264
};
265
266
GLSR.showFormMessage = function( response )
267
{
268
	var formIdEl  = GLSR.activeForm.querySelector( 'input[name="form_id"]' );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
269
	var messageEl = GLSR.activeForm.querySelector( '.glsr-form-messages' );
270
	if( messageEl === null ) {
271
		messageEl = GLSR.insertAfter( formIdEl, 'div', {
272
			'class': 'glsr-form-messages',
273
		});
274
	}
275
	if( !!response.errors ) {
276
		GLSR.addClass( messageEl, 'gslr-has-errors' );
277
	}
278
	else {
279
		GLSR.removeClass( messageEl, 'gslr-has-errors' );
280
	}
281
	messageEl.innerHTML = '<p>' + response.message + '</p>';
282
};
283
284
GLSR.submitForm = function( recaptchaToken )
285
{
286
	GLSR.activeForm.querySelector( '[type="submit"]' ).setAttribute( 'disabled', '' );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
287
	GLSR.postAjax( site_reviews.ajaxurl, GLSR.buildFormData( recaptchaToken ), function( response ) {
0 ignored issues
show
Bug introduced by
The variable site_reviews seems to be never declared. If this is a global, consider adding a /** global: site_reviews */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
288
		// console.log( response );
289
		if( response.recaptcha === true ) {
290
			// console.log( 'executing recaptcha' );
291
			return GLSR.recaptcha.execute();
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
292
		}
293
		if( response.recaptcha === 'reset' ) {
294
			// console.log( 'reseting failed recaptcha' );
295
			GLSR.recaptcha.reset();
296
		}
297
		if( response.errors === false ) {
298
			// console.log( 'reseting recaptcha' );
299
			GLSR.recaptcha.reset();
300
			GLSR.activeForm.reset();
301
		}
302
		// console.log( 'submission finished' );
303
		GLSR.showFormErrors( response.errors );
304
		GLSR.showFormMessage( response );
305
		GLSR.enableSubmitButton();
306
		response.form = GLSR.activeForm;
307
		document.dispatchEvent( new CustomEvent( 'site-reviews/after/submission', { detail: response }));
0 ignored issues
show
Bug introduced by
The variable CustomEvent seems to be never declared. If this is a global, consider adding a /** global: CustomEvent */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
308
		GLSR.activeForm = null;
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
309
	});
310
};
311
312
GLSR.on( 'change', 'form.glsr-submit-review-form', function( ev )
313
{
314
	GLSR.clearFieldError( ev.target );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
315
});
316
317
GLSR.on( 'submit', 'form.glsr-submit-review-form', function( ev )
318
{
319
	if( GLSR.hasClass( this, 'no-ajax' ))return;
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
320
	ev.preventDefault();
321
	GLSR.activeForm = this;
322
	GLSR.recaptcha.addListeners();
323
	GLSR.clearFormErrors();
324
	GLSR.submitForm();
325
});
326
327
/**
328
 * This event function exists to undo the mayhem caused by the invisible-recaptcha plugin
329
 * This function is triggered on the invisible-recaptcha callback
330
 */
331
GLSR.on( 'click', '.glsr-field [type="submit"]', function()
332
{
333
	this.closest( 'form' ).onsubmit = null;
334
	HTMLFormElement.prototype._submit = HTMLFormElement.prototype.submit;
0 ignored issues
show
Bug introduced by
The variable HTMLFormElement seems to be never declared. If this is a global, consider adding a /** global: HTMLFormElement */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
335
	HTMLFormElement.prototype.submit = function() {
336
		var token = this.querySelector( '#g-recaptcha-response' );
337
		if( null === token || null === this.querySelector( '.glsr-field' )) {
338
			this._submit();
339
		}
340
		else {
341
			GLSR.submitForm( token.value );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
342
		}
343
	};
344
});
345
346
GLSR.on( 'click', '.glsr-ajax-navigation a', GLSR.onClickPagination );
347
348
GLSR.ready( function()
349
{
350
	GLSR.createExceprts();
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
351
	GLSR.createStarRatings();
352
});
353